package com.voxel.sense.infomsg.module.publish.personal;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.com.common.view.recycler.RecyclerAdapter;
import com.voxel.sense.infomsg.R;
import cyy.example.com.facotry.share.SPEngine;
import cyy.example.com.facotry.model.api.MyPublishListEntity;
import cyy.example.com.facotry.Factory;
import com.voxel.sense.infomsg.utils.GlideUtils;

import butterknife.BindView;

/**
 * Created by ChenYiYao on 2018/9/5.
 */
public class MyPublishAdapter extends RecyclerAdapter<MyPublishListEntity> {
    @Override
    protected int getItemViewType(int position, MyPublishListEntity data) {
        return R.layout.item_recycler_my_publish;
    }

    @Override
    protected ViewHolder onCreateViewHolder(View root, int viewType) {
        return new Viewholder(root);
    }


    class Viewholder extends ViewHolder<MyPublishListEntity> {
        @BindView(R.id.iv_portrait)
        ImageView iv_portrait;//头像
        @BindView(R.id.tv_name)
        TextView tv_name; //发布人
        @BindView(R.id.tv_time)
        TextView tv_time; //发布时间
        @BindView(R.id.tv_firm_name)
        TextView tv_firm_name; //公司名
        @BindView(R.id.tv_address)
        TextView tv_address; //地址
        @BindView(R.id.iv_location)
        ImageView iv_location; //地址icon

        public Viewholder(View itemView) {
            super(itemView);
        }

        @Override
        protected void onBind(MyPublishListEntity data) {
            SPEngine.UserInfo userInfo = SPEngine.getSPEngine().getUserInfo();
            String portrait = userInfo.getPortrait();

            GlideUtils.GlideLoadPortrait(Factory.app(), portrait, iv_portrait);
            tv_name.setText(data.getCreateName());
            tv_time.setText(data.getCreateTime());
            tv_firm_name.setText(data.getCompanyName());

            String detailAddr = data.getDetailAddr();


            if (TextUtils.isEmpty(detailAddr)) {
                iv_location.setVisibility(View.GONE);
                tv_address.setVisibility(View.GONE);
            } else {
                iv_location.setVisibility(View.VISIBLE);
                tv_address.setVisibility(View.VISIBLE);
                tv_address.setText(data.getDetailAddr());
            }
        }
    }

}
